package com.atguigu.lambda;
import org.junit.Test;

import java.util.Comparator;

//Lambda表达式的使用举例:
public class LambdaTest {
    @Test
    public void test(){
        Runnable r1=new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱北京");
            }
        };
        r1.run();
        System.out.println("*************************");
        Runnable r2=()-> System.out.println("我爱hzl");//lambda表达式
        r2.run();
    }
    @Test
    public void test2(){
        Comparator<Integer> com1=new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
        System.out.println(com1.compare(12, 21)); //-1
        System.out.println("*******************");
        Comparator<Integer> com2=(o1,o2)->Integer.compare(o1,o2);//lambda表达式写法
        System.out.println(com2.compare(12, 26));
        System.out.println("************************");
        //方法引用的写法
        Comparator<Integer> com3=Integer::compare;
    }
}
